<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            body{
                background-color: lavender;
            }
            table{
                border :solid black 1px;
                margin :20px;
                background-color: white;
                
            }
            tr{
               border :solid black 1px;
               padding: 10px;
            }
            td{
                border :solid black 1px;
                padding: 10px;
            }
        </style>
    </head>
    <body>
         <?php
        $serveur="localhost"; 
        $user="root"; 
        $password="root";
        $database="carnet_adresses";
        $connexion_serveur = mysqli_connect($serveur, $user, $password,$database);
        
      
        $sql = "SELECT * FROM entreprises "; 
        $croissant = "SELECT * FROM entreprises ORDER BY raison_sociale ASC";
        $decroissant = "SELECT * FROM entreprises ORDER BY raison_sociale DESC";
        $req = mysqli_query($connexion_serveur, $sql);
        $nbre_total = mysqli_num_rows($req)
       
         ?>
        <h1>Liste des entreprises</h1>
        <div>Nombres d'entreprise affichées : <?php echo $nbre_total; ?></div><br>
        <form action="" method="post">
        <button type="submit" name="button">croissant</button>
        <button type="submit" name="button2">decroissant</button>
        <button type="submit" name="button3">Tout</button>
        </form>
        
        <?php
        //si le bouton de tri asc est pressé
        if(isset($_POST["button"])){
        $envoi_requete = mysqli_query($connexion_serveur, $croissant);
        while($resultats = mysqli_fetch_assoc($envoi_requete)) {
            
                 ?>
            
   <table>
     <tr>
      <td>Numero :</td>
      <td><?php echo $resultats['id']?></td>
     </tr>  
     <tr>
      <td>Raison sociale</td>
      <td><a href="liste_contacts.php?id=<?php echo $resultats['id']?>"><?php echo $resultats['raison_sociale']?></a></td>
     </tr>
     <tr>
     <td>Adresse</td>
      <td><?php echo $resultats['adresse']?></td>
     </tr>
      <tr>
      <td>Telephone</td>
      <td><?php echo $resultats['telephone']?></td>
     </tr>
     <tr>
      <td>Fax</td>
      <td><?php echo $resultats['fax']?></td>
     </tr>
     <tr>
      <td>Email</td>
      <td><?php echo $resultats['email']?></td>
     </tr>
     <tr>
      <td>Observation</td>
      <td><?php echo $resultats['observations']?></td>
     </tr>
   </table>
        
      <?php  }
      
            
            
            
        }elseif(isset($_POST["button2"])){
             //si le bouton
        $envoi_requete = mysqli_query($connexion_serveur, $decroissant);
        while($resultats = mysqli_fetch_assoc($envoi_requete)) {
            
                 ?>
            
   <table>
     <tr>
      <td>Numero :</td>
      <td><?php echo $resultats['id']?></td>
     </tr>
     <tr>
      <td>Raison sociale</td>
      <td><a href="liste_contacts.php?id=<?php echo $resultats['id']?>"><?php echo $resultats['raison_sociale']?></a></td>
     </tr>
     <tr>
     <td>Adresse</td>
      <td><?php echo $resultats['adresse']?></td>
     </tr>
      <tr>
      <td>Telephone</td>
      <td><?php echo $resultats['telephone']?></td>
     </tr>
     <tr>
      <td>Fax</td>
      <td><?php echo $resultats['fax']?></td>
     </tr>
     <tr>
      <td>Email</td>
      <td><?php echo $resultats['email']?></td>
     </tr>
     <tr>
      <td>Observation</td>
      <td><?php echo $resultats['observations']?></td>
     </tr>
   </table>
        
      <?php  }
        
      
            
        }elseif(isset($_POST["button3"])){
             //sinon  normal
        $envoi_requete = mysqli_query($connexion_serveur, $sql);
        while($resultats = mysqli_fetch_assoc($envoi_requete)) {
            
                 ?>
            
   <table>
     <tr>
      <td>Numero :</td>
      <td><?php echo $resultats['id']?></td>
     </tr>
     <tr>
     
     <td>Raison sociale</td>
     <td><a href="liste_contacts.php?id=<?php echo $resultats['id']?>"><?php echo $resultats['raison_sociale']?></a></td>
     </tr>
     <tr>
     <td>Adresse</td>
      <td><?php echo $resultats['adresse']?></td>
     </tr>
      <tr>
      <td>Telephone</td>
      <td><?php echo $resultats['telephone']?></td>
     </tr>
     <tr>
      <td>Fax</td>
      <td><?php echo $resultats['fax']?></td>
     </tr>
     <tr>
      <td>Email</td>
      <td><?php echo $resultats['email']?></td>
     </tr>
     <tr>
      <td>Observation</td>
      <td><?php echo $resultats['observations']?></td>
     </tr>
   </table>
        
      <?php  }
        }else{
             //sinon  normal
        $envoi_requete = mysqli_query($connexion_serveur, $sql);
        while($resultats = mysqli_fetch_assoc($envoi_requete)) {
            
                 ?>
            
   <table>
     <tr>
      <td>Numero :</td>
      <td><?php echo $resultats['id']?></td>
     </tr>
     <tr>
      <td>Raison sociale</td>
      <td><a href="liste_contacts.php?id=<?php echo $resultats['id']?>"><?php echo $resultats['raison_sociale']?></a></td>
     </tr>
     <tr>
     <td>Adresse</td>
      <td><?php echo $resultats['adresse']?></td>
     </tr>
      <tr>
      <td>Telephone</td>
      <td><?php echo $resultats['telephone']?></td>
     </tr>
     <tr>
      <td>Fax</td>
      <td><?php echo $resultats['fax']?></td>
     </tr>
     <tr>
      <td>Email</td>
      <td><?php echo $resultats['email']?></td>
     </tr>
     <tr>
      <td>Observation</td>
      <td><?php echo $resultats['observations']?></td>
     </tr>
   </table>
        
      <?php  }
        }
        
        
       
        
      
        ?>
    </body>
</html>
